package com.enen.service.impl;

import com.enen.mapper.StudentMapper;
import com.enen.pojo.Clazz;
import com.enen.pojo.PageResult;
import com.enen.pojo.Student;
import com.enen.pojo.StudentQueryParam;
import com.enen.service.StudentService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;

    // 分页查询学员信息
    @Override
    public PageResult<Student> findAll(StudentQueryParam studentQueryParam) {
        //1.设置分页参数(PageHelper)
        PageHelper.startPage(studentQueryParam.getPage(),studentQueryParam.getPageSize());
        //2.执行查询
        List<Student> clazzList = studentMapper.findAll(studentQueryParam);
        //3.解析查询结果，并封装
        Page<Student> p =(Page<Student>)clazzList;
        return new PageResult<Student>(p.getTotal(),p.getResult());
    }
    // 添加学员信息
    @Override
    public void save(Student student) {
        student.setCreateTime(LocalDateTime.now());
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.save(student);
    }
    // 根据id查询学员信息
    @Override
    public Student getInfo(Integer id) {
        return studentMapper.getInfo(id);
    }
    // 根据id删除学员信息
    @Override
    public void delect(List<Integer> ids) {
        studentMapper.delect(ids);
    }
    // 修改学员信息
    @Override
    public void update(Student student) {
        student.setUpdateTime(LocalDateTime.now());
        studentMapper.update(student);
    }
    // 违规处理
    @Override
    public void violation(Integer id, Integer score) {
        studentMapper.violation(id,score);
    }
}
